/**
 * @author zly
 */
(function($){

	$(document).ready(function(){
		validateForm();
	});
	
	function validateForm() {
		jQuery.validator.addMethod(
			"goodtel",
			function(value,element){
				return /^\d{3,4}[-]\d{7,8}$/.test(element.value);  	
			},
			"格式为010-1234567"
		);
		
		$("#vip form.form_vip").validate({
			rules: {
				"profile[auth_no]": "required",
				"profile[reg_no]": "required",
				"profile[company]": "required",
				"profile[name]": "required",
				"profile[com_full_address]": "required",
				"profile[zip_code]":{
					required: true,
					digits: true,
					rangelength: [6,6]
				},
				"profile[tel]": {
					required: true,
					goodtel: true
				},
				"profile[mobile]": {
					required: true,
					digits: true,
					rangelength: [11,11]
				},
				"profile[email]": {
					email: true  
				},
				"profile[qq]":{
					digits: true
				}
			},
			messages: {
				"profile[auth_no]": "请输入授权号",
				"profile[reg_no]": "请输入工商注册号",
				"profile[company]": "请输入公司名称",
				"profile[name]": "请输入您的名字",
				"profile[com_full_address]": "请输入公司详细地址",
				"profile[zip_code]": {
					required: "请输入邮政编码",
					digits: "邮政编码必须为数字",
					rangelength: "邮政编码长度为6"
				},
				"profile[tel]": {
					required: "请输入固定电话",
					goodtel: "格式为010-1234567"
				},
				"profile[mobile]": {
					required: "请输入移动电话",
					digits: "移动电话为数字",
					rangelength: "移动电话长度为11"
				},
				"profile[email]": {
					email: "请输入有效的电子邮件"
				},
				"profile[qq]": {
					digits: "qq号为数字"
				}
			},
			errorPlacement: function(error, element) {
				error.appendTo( element.parent() );
			},
			success: function(label) {
 			// set &nbsp; as text for IE
 			label.html("&nbsp;").addClass("checked");
 			},
			submitHandler: function(form) {
				form.submit();
			}
		});	
	}

})(jQuery);